package com.huang.wangpan.utils;

import com.huang.wangpan.dto.FileIm;
import com.huang.wangpan.vo.UserFile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class VoToBean {
    @Value("${file.warehouse}")
    private String fileWarehouse;

    private static String fileWarehouseStr;

    // 折中赋值
    @PostConstruct
    public void init() {
        fileWarehouseStr = FileUtil.getCurrentPath() + fileWarehouse;
    }

    public static UserFile fileimToUserFile(FileIm fim, String name, String currentpath) {
        UserFile uf = new UserFile();
        uf.setFilesize(fim.getFilesize());
        uf.setIconSign(fim.getIconsign());
        uf.setMtime(fim.getMtime());
        uf.setName(name);
        uf.setVirtualpath(currentpath + fim.getFilename());
        if (!"#icon-folder".equals(fim.getIconsign().trim())) {
            uf.setRealpath(fileWarehouseStr + fim.getFilename());
        }
        return uf;
    }
}
